<?php
  require_once('tpl/header.php');
?>
<?php 
    require_once('../system/dbConn.php');
	connect();
	require_once('../system/loginCheck.php');

	//接收表单元素
	//胜利ar_dump($_POST);
	$vid=$_POST["vid"];
	$videoname=$_POST["videoname"];
	$videotype=$_POST["videotype"];
	$intro=$_POST["intro"];
	$address=$_POST["address"];

	//处理文件上传
	if ($_FILES["pic"]["error"]) 
    {
        switch ($_FILES["pic"]["error"])
        {
        	case '1':
        		echo "文件尺寸超出了配置文件的最大值";
        		break;
        	case '3':
        		echo "部分文件上传";
        		break;
        	case '4':
        		echo "没有上传文件";
        		$sql="update videos set videoname='$videoname',tid=$videotype,intro='$intro',address='$address' where vid=$vid";
        		break;
            default:
        		echo "未知错误";
        		break;
        	}
        }  
    else//上传了新的海报图片
    {
    	$arr=explode(".", $_FILES["pic"]["name"]);
  		$suffix=$arr[count($arr)-1];
  		$allowtype=array("jpg","jpeg","png","PNG","JPG","JPEG","Bmp","gif");
  		if(!in_array($suffix,$allowtype))
  		{
       		//扩展名不在allowtype中
    		// echo "文件类型不是图片类型";
    		// exit;//php脚本退出结束
    		die("文件类型不是图片类型，请重新选择");
  		}
    	$filePath="../posters/";
  		$randname=date("YmdHis").rand(100,999).".".$suffix;

    	if (move_uploaded_file($_FILES["pic"]["tmp_name"],$filePath.$randname)) 
    	{
    		echo "海报文件图片上传成功<br>";
    		$sql="select * from videos where vid=$vid";
			$result=mysql_query($sql);
			$row=mysql_fetch_assoc($result);
			$filename=$filePath.$row["pic"];
			if(file_exists($filename))
				unlink($filename);
    	}
    	$sql="update videos set videoname='$videoname',tid=$videotype,pic='$randname',intro='$intro',address='$address' where vid=$vid";
    }
    //echo $sql."<br>";
    $result=mysql_query($sql);
    if ($result==1) 
    {
    	echo "更新成功，3s后返回列表页";
    	header("refresh:3;url='videoList.php'");
    } 
    else 
    {
    	echo "更新失败";
    }

 ?>
   


<?php
  require_once('tpl/footer.php');
?>
